package com.desheng.bigdata.ds.stack;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @Description 通过链表来模拟栈结构（FIFO）
 * @Author deshenglijun
 * @Date 2020/5/13 21:35
 * @Version 1.0
 */
public class Stack2<E> implements Iterable<E> {
    private LinkedList<E> list = new LinkedList<>();


    public boolean isEmpty() {
        return list.size() == 0;
    }

    public int size() {
        return list.size();
    }

    public void push(E e) {
        list.addFirst(e);
    }

    public E pop() {
        return list.removeFirst();
    }

    @Override
    public Iterator<E> iterator() {
        return list.iterator();
    }
}
